from scipy.stats import percentileofscore
from research.calcor import calcor_base
class fenweishu(calcor_base):
    def __init__(self,timeperiod=60,mintimeperiod=None,ascending=True):
        super().__init__(timeperiod=timeperiod,mintimeperiod=mintimeperiod,datatype="dimn")
        self.ascending=ascending
    def calc(self):
        data=self.hisdata
        rst=percentileofscore(data, data[-1])
        if not self.ascending:
            rst=1-rst
        return rst
class fenweishu_byargs:#box整理
    def __init__(self,ascending=True):
        self.ascending=ascending
    def oncalc(self,*d,timekey=None):
        data = d
        rst = percentileofscore(data, data[-1])
        if not self.ascending:
            rst = 1 - rst
        return rst
class fenweishu_byobjs:#box整理
    def __init__(self,ascending=True):
        self.ascending=ascending
    def oncalc(self,d,timekey=None):
        data = d
        rst = percentileofscore(data, data[-1])
        if not self.ascending:
            rst = 1 - rst
        return rst